/**
 *
 */
import Util;
import OpenApi;
import OpenApiUtil;
import EndpointUtil;

extends OpenApi;


init(config: OpenApi.Config){
  super(config);
  @endpointRule = 'central';
  @endpointMap = {
    cn-beijing = 'openanalytics.cn-beijing.aliyuncs.com',
    cn-zhangjiakou = 'openanalytics.cn-zhangjiakou.aliyuncs.com',
    cn-hangzhou = 'openanalytics.cn-hangzhou.aliyuncs.com',
    cn-shanghai = 'openanalytics.cn-shanghai.aliyuncs.com',
    cn-shenzhen = 'openanalytics.cn-shenzhen.aliyuncs.com',
    cn-hongkong = 'openanalytics.cn-hongkong.aliyuncs.com',
    ap-southeast-1 = 'openanalytics.ap-southeast-1.aliyuncs.com',
    ap-southeast-2 = 'datalakeanalytics.ap-southeast-2.aliyuncs.com',
    ap-southeast-3 = 'openanalytics.ap-southeast-3.aliyuncs.com',
    ap-northeast-1 = 'datalakeanalytics.ap-northeast-1.aliyuncs.com',
    eu-west-1 = 'openanalytics.eu-west-1.aliyuncs.com',
    us-west-1 = 'openanalytics.us-west-1.aliyuncs.com',
    us-east-1 = 'datalakeanalytics.us-east-1.aliyuncs.com',
    eu-central-1 = 'datalakeanalytics.eu-central-1.aliyuncs.com',
    ap-south-1 = 'openanalytics.ap-south-1.aliyuncs.com',
    ap-northeast-2-pop = 'openanalytics.ap-northeast-1.aliyuncs.com',
    ap-southeast-5 = 'openanalytics.ap-southeast-5.aliyuncs.com',
    cn-beijing-finance-1 = 'openanalytics.aliyuncs.com',
    cn-beijing-finance-pop = 'openanalytics.aliyuncs.com',
    cn-beijing-gov-1 = 'openanalytics.aliyuncs.com',
    cn-beijing-nu16-b01 = 'openanalytics.aliyuncs.com',
    cn-chengdu = 'openanalytics.aliyuncs.com',
    cn-edge-1 = 'openanalytics.aliyuncs.com',
    cn-fujian = 'openanalytics.aliyuncs.com',
    cn-haidian-cm12-c01 = 'openanalytics.aliyuncs.com',
    cn-hangzhou-bj-b01 = 'openanalytics.aliyuncs.com',
    cn-hangzhou-finance = 'openanalytics.aliyuncs.com',
    cn-hangzhou-internal-prod-1 = 'openanalytics.aliyuncs.com',
    cn-hangzhou-internal-test-1 = 'openanalytics.aliyuncs.com',
    cn-hangzhou-internal-test-2 = 'openanalytics.aliyuncs.com',
    cn-hangzhou-internal-test-3 = 'openanalytics.aliyuncs.com',
    cn-hangzhou-test-306 = 'openanalytics.aliyuncs.com',
    cn-hongkong-finance-pop = 'openanalytics.aliyuncs.com',
    cn-huhehaote = 'openanalytics.cn-huhehaote.aliyuncs.com',
    cn-north-2-gov-1 = 'openanalytics.aliyuncs.com',
    cn-qingdao = 'openanalytics.cn-qingdao.aliyuncs.com',
    cn-qingdao-nebula = 'openanalytics.aliyuncs.com',
    cn-shanghai-et15-b01 = 'openanalytics.aliyuncs.com',
    cn-shanghai-et2-b01 = 'openanalytics.aliyuncs.com',
    cn-shanghai-finance-1 = 'openanalytics.aliyuncs.com',
    cn-shanghai-inner = 'openanalytics.aliyuncs.com',
    cn-shanghai-internal-test-1 = 'openanalytics.aliyuncs.com',
    cn-shenzhen-finance-1 = 'openanalytics.aliyuncs.com',
    cn-shenzhen-inner = 'openanalytics.aliyuncs.com',
    cn-shenzhen-st4-d01 = 'openanalytics.aliyuncs.com',
    cn-shenzhen-su18-b01 = 'openanalytics.aliyuncs.com',
    cn-wuhan = 'openanalytics.aliyuncs.com',
    cn-yushanfang = 'openanalytics.aliyuncs.com',
    cn-zhangbei-na61-b01 = 'openanalytics.aliyuncs.com',
    cn-zhangjiakou-na62-a01 = 'openanalytics.aliyuncs.com',
    cn-zhengzhou-nebula-1 = 'openanalytics.aliyuncs.com',
    eu-west-1-oxs = 'openanalytics.ap-northeast-1.aliyuncs.com',
    me-east-1 = 'openanalytics.me-east-1.aliyuncs.com',
    rus-west-1-pop = 'openanalytics.ap-northeast-1.aliyuncs.com',
  };

  checkConfig(config);
  @endpoint = getEndpoint('openanalytics-open', @regionId, @endpointRule, @network, @suffix, @endpointMap, @endpoint);
}

function getEndpoint(productId: string, regionId: string, endpointRule: string, network: string, suffix: string, endpointMap: map[string]string, endpoint: string) throws: string{
  if (!Util.empty(endpoint)) {
    return endpoint;
  }
  
  if (!Util.isUnset(endpointMap) && !Util.empty(endpointMap[regionId])) {
    return endpointMap[regionId];
  }
  return EndpointUtil.getEndpointRules(productId, regionId, endpointRule, network, suffix);
}

model CancelSparkStatementRequest {
  jobId?: string(name='JobId', description='This parameter is required.', example='j202106071620hangzhou****'),
  statementId?: string(name='StatementId', description='This parameter is required.', example='2026****'),
}

model CancelSparkStatementResponseBody = {
  data?: string(name='Data', example='true'),
  requestId?: string(name='RequestId', example='341ADFA1-4A68-4707-9CA7-FA86523A5F14'),
}

model CancelSparkStatementResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: CancelSparkStatementResponseBody(name='body'),
}

/**
 * @param request CancelSparkStatementRequest
 * @param runtime runtime options for this request RuntimeOptions
 * @return CancelSparkStatementResponse
 */
async function cancelSparkStatementWithOptions(request: CancelSparkStatementRequest, runtime: Util.RuntimeOptions): CancelSparkStatementResponse {
  Util.validateModel(request);
  var body : map[string]any = {};
  if (!Util.isUnset(request.jobId)) {
    body['JobId'] = request.jobId;
  }
  if (!Util.isUnset(request.statementId)) {
    body['StatementId'] = request.statementId;
  }
  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'CancelSparkStatement',
    version = '2018-06-19',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

/**
 * @param request CancelSparkStatementRequest
 * @return CancelSparkStatementResponse
 */
async function cancelSparkStatement(request: CancelSparkStatementRequest): CancelSparkStatementResponse {
  var runtime = new Util.RuntimeOptions{};
  return cancelSparkStatementWithOptions(request, runtime);
}

model CreateInstanceRequest {
  chargeType?: string(name='ChargeType', description='This parameter is required.', example='POSTPAY'),
  component?: string(name='Component', description='This parameter is required.', example='"{\\\\"operable\\\\":\\\\"false\\\\",\\\\"max_cu\\\\":\\\\"8\\\\",\\\\"instance_name\\\\":\\\\"api-test-9\\\\",\\\\"min_cu\\\\":\\\\"0\\\\",\\\\"engine\\\\":\\\\"spark\\\\",\\\\"region\\\\":\\\\"cn-hangzhou\\\\",\\\\"app_name\\\\":\\\\"xx\\\\",\\\\"app_version_name\\\\":\\\\"xx\\\\"}"'),
  instanceType?: string(name='InstanceType', description='This parameter is required.', example='CU_PRESTO'),
  regionId?: string(name='RegionId', example='cn-beijing'),
}

model CreateInstanceResponseBody = {
  errorCode?: string(name='ErrorCode', example='600'),
  errorInfo?: string(name='ErrorInfo', example='An internal error occurred'),
  requestId?: string(name='RequestId', example='312F48C7-AFA0-46AA-B8F6-1B16B8808045'),
  result?: string(name='Result', example='true'),
  success?: boolean(name='Success', example='true'),
}

model CreateInstanceResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: CreateInstanceResponseBody(name='body'),
}

/**
 * @param request CreateInstanceRequest
 * @param runtime runtime options for this request RuntimeOptions
 * @return CreateInstanceResponse
 */
async function createInstanceWithOptions(request: CreateInstanceRequest, runtime: Util.RuntimeOptions): CreateInstanceResponse {
  Util.validateModel(request);
  var body : map[string]any = {};
  if (!Util.isUnset(request.chargeType)) {
    body['ChargeType'] = request.chargeType;
  }
  if (!Util.isUnset(request.component)) {
    body['Component'] = request.component;
  }
  if (!Util.isUnset(request.instanceType)) {
    body['InstanceType'] = request.instanceType;
  }
  if (!Util.isUnset(request.regionId)) {
    body['RegionId'] = request.regionId;
  }
  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'CreateInstance',
    version = '2018-06-19',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

/**
 * @param request CreateInstanceRequest
 * @return CreateInstanceResponse
 */
async function createInstance(request: CreateInstanceRequest): CreateInstanceResponse {
  var runtime = new Util.RuntimeOptions{};
  return createInstanceWithOptions(request, runtime);
}

model ExecuteSparkStatementRequest {
  code?: string(name='Code', description='This parameter is required.', example='print(2+2)\\\\n'),
  jobId?: string(name='JobId', description='This parameter is required.', example='j202106071620hangzhou****'),
  kind?: string(name='Kind', example='sql'),
}

model ExecuteSparkStatementResponseBody = {
  data?: string(name='Data', example='2'),
  requestId?: string(name='RequestId', example='0DC5B6F080E8-0DC5B6F080E8-0DC5B'),
}

model ExecuteSparkStatementResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: ExecuteSparkStatementResponseBody(name='body'),
}

/**
 * @param request ExecuteSparkStatementRequest
 * @param runtime runtime options for this request RuntimeOptions
 * @return ExecuteSparkStatementResponse
 */
async function executeSparkStatementWithOptions(request: ExecuteSparkStatementRequest, runtime: Util.RuntimeOptions): ExecuteSparkStatementResponse {
  Util.validateModel(request);
  var body : map[string]any = {};
  if (!Util.isUnset(request.code)) {
    body['Code'] = request.code;
  }
  if (!Util.isUnset(request.jobId)) {
    body['JobId'] = request.jobId;
  }
  if (!Util.isUnset(request.kind)) {
    body['Kind'] = request.kind;
  }
  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'ExecuteSparkStatement',
    version = '2018-06-19',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

/**
 * @param request ExecuteSparkStatementRequest
 * @return ExecuteSparkStatementResponse
 */
async function executeSparkStatement(request: ExecuteSparkStatementRequest): ExecuteSparkStatementResponse {
  var runtime = new Util.RuntimeOptions{};
  return executeSparkStatementWithOptions(request, runtime);
}

model GetJobAttemptLogRequest {
  jobAttemptId?: string(name='JobAttemptId', description='This parameter is required.', example='j202105272322hangzhou5d64f1560000128-0001'),
  jobId?: string(name='JobId', description='This parameter is required.', example='j202105272322hangzhou5d64f1560000128'),
  vcName?: string(name='VcName', description='This parameter is required.', example='release-test'),
}

model GetJobAttemptLogResponseBody = {
  data?: string(name='Data', example='local:///opt/spark/jars/offline-sql.jar, main_file\\\\n+ exec /usr/bin/tini -s -- /jdk/jdk8/bin/java -cp \\\\"/opt/tools/exec-wrapper.jar:.:::/opt/spark/jars/*\\\\" com.aliyun.dla.spark.SparkJobWrapper /opt/spark/bin/spark-submit --conf spark.driver.host=172.16.6.205 --conf spark.ui.port=4040 --conf \\\\"spark.driver.extraJavaOptions=-Dlog4j.configuration=file:///opt/spark/log-conf/log4j.properties -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/tmp/dump.hprof -XX:OnOutOfMemoryError=\\\\"bash /opt/tools/oss-cp.sh /tmp/dump.hprof oss://dla-test-cn-hangzhou/spark-logs/release-test/j202105272322hangzhou5d64f1560000128-0001/driver/dump.hprof; bash /opt/tools/job-stop.sh\\\\" \\\\"'),
  requestId?: string(name='RequestId', example='9CE8F271-F918-43B6-8F58-F9F1C2DCFDB8'),
}

model GetJobAttemptLogResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: GetJobAttemptLogResponseBody(name='body'),
}

/**
 * @param request GetJobAttemptLogRequest
 * @param runtime runtime options for this request RuntimeOptions
 * @return GetJobAttemptLogResponse
 */
async function getJobAttemptLogWithOptions(request: GetJobAttemptLogRequest, runtime: Util.RuntimeOptions): GetJobAttemptLogResponse {
  Util.validateModel(request);
  var body : map[string]any = {};
  if (!Util.isUnset(request.jobAttemptId)) {
    body['JobAttemptId'] = request.jobAttemptId;
  }
  if (!Util.isUnset(request.jobId)) {
    body['JobId'] = request.jobId;
  }
  if (!Util.isUnset(request.vcName)) {
    body['VcName'] = request.vcName;
  }
  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'GetJobAttemptLog',
    version = '2018-06-19',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

/**
 * @param request GetJobAttemptLogRequest
 * @return GetJobAttemptLogResponse
 */
async function getJobAttemptLog(request: GetJobAttemptLogRequest): GetJobAttemptLogResponse {
  var runtime = new Util.RuntimeOptions{};
  return getJobAttemptLogWithOptions(request, runtime);
}

model GetJobDetailRequest {
  jobId?: string(name='JobId', description='This parameter is required.', example='j202010271622hangzhouf742a4330000923'),
  vcName?: string(name='VcName', description='This parameter is required.', example='MyCluster'),
}

model GetJobDetailResponseBody = {
  jobDetail?: {
    createTime?: string(name='CreateTime', example='2020-10-27 16:23:16'),
    createTimeValue?: string(name='CreateTimeValue', example='1603786996000'),
    detail?: string(name='Detail', example='{\\\\"args\\\\":[\\\\"100\\\\"],\\\\"name\\\\":\\\\"SparkPi\\\\",\\\\"className\\\\":\\\\"org.apache.spark.examples.SparkPi\\\\",\\\\"conf\\\\":{\\\\"spark.driver.resourceSpec\\\\":\\\\"medium\\\\",\\\\"spark.executor.instances\\\\":5,\\\\"spark.executor.resourceSpec\\\\":\\\\"medium\\\\"},\\\\"file\\\\":\\\\"local:///tmp/spark-examples.jar\\\\"}'),
    driverResourceSpec?: string(name='DriverResourceSpec', example='small'),
    executorInstances?: string(name='ExecutorInstances', example='1'),
    executorResourceSpec?: string(name='ExecutorResourceSpec', example='small'),
    jobId?: string(name='JobId', example='j202010271622hangzhouf742a4330000923'),
    jobName?: string(name='JobName', example='SparkPi'),
    lastJobAttemptId?: string(name='LastJobAttemptId', example='202105251618hzslot9906b0b40000005-0001'),
    sparkUI?: string(name='SparkUI', example='https://dlaui-cn-hangzhou.aliyuncs.com/?token=xxx'),
    status?: string(name='Status', example='success'),
    submitTime?: string(name='SubmitTime', example='2020-10-27 16:23:16'),
    submitTimeValue?: string(name='SubmitTimeValue', example='1603786996000'),
    updateTime?: string(name='UpdateTime', example='2020-10-27 16:23:16'),
    updateTimeValue?: string(name='UpdateTimeValue', example='1603786996000'),
    vcName?: string(name='VcName', example='MyCluster'),
  }(name='JobDetail'),
  requestId?: string(name='RequestId', example='5F10AB6E-8984-4E32-B821-4E1512711B8C'),
}

model GetJobDetailResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: GetJobDetailResponseBody(name='body'),
}

/**
 * @param request GetJobDetailRequest
 * @param runtime runtime options for this request RuntimeOptions
 * @return GetJobDetailResponse
 */
async function getJobDetailWithOptions(request: GetJobDetailRequest, runtime: Util.RuntimeOptions): GetJobDetailResponse {
  Util.validateModel(request);
  var body : map[string]any = {};
  if (!Util.isUnset(request.jobId)) {
    body['JobId'] = request.jobId;
  }
  if (!Util.isUnset(request.vcName)) {
    body['VcName'] = request.vcName;
  }
  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'GetJobDetail',
    version = '2018-06-19',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

/**
 * @param request GetJobDetailRequest
 * @return GetJobDetailResponse
 */
async function getJobDetail(request: GetJobDetailRequest): GetJobDetailResponse {
  var runtime = new Util.RuntimeOptions{};
  return getJobDetailWithOptions(request, runtime);
}

model GetJobLogRequest {
  jobId?: string(name='JobId', description='This parameter is required.', example='j202010271622hangzhouf742a4330000923'),
  vcName?: string(name='VcName', description='This parameter is required.', example='MyCluster'),
}

model GetJobLogResponseBody = {
  data?: string(name='Data', example='INFO SparkContext: Running Spark version 2.x'),
  requestId?: string(name='RequestId', example='EC031B4B-3E07-40D2-9BC5-xxxx'),
}

model GetJobLogResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: GetJobLogResponseBody(name='body'),
}

/**
 * @param request GetJobLogRequest
 * @param runtime runtime options for this request RuntimeOptions
 * @return GetJobLogResponse
 */
async function getJobLogWithOptions(request: GetJobLogRequest, runtime: Util.RuntimeOptions): GetJobLogResponse {
  Util.validateModel(request);
  var body : map[string]any = {};
  if (!Util.isUnset(request.jobId)) {
    body['JobId'] = request.jobId;
  }
  if (!Util.isUnset(request.vcName)) {
    body['VcName'] = request.vcName;
  }
  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'GetJobLog',
    version = '2018-06-19',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

/**
 * @param request GetJobLogRequest
 * @return GetJobLogResponse
 */
async function getJobLog(request: GetJobLogRequest): GetJobLogResponse {
  var runtime = new Util.RuntimeOptions{};
  return getJobLogWithOptions(request, runtime);
}

model GetJobStatusRequest {
  jobId?: string(name='JobId', description='This parameter is required.', example='j202011031935hangzhouf742a4330003667'),
  vcName?: string(name='VcName', description='This parameter is required.', example='MyCluster'),
}

model GetJobStatusResponseBody = {
  requestId?: string(name='RequestId', example='5C3F9ADD-2350-4C21-A3A1-A906F8DF8016'),
  status?: string(name='Status', example='success'),
}

model GetJobStatusResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: GetJobStatusResponseBody(name='body'),
}

/**
 * @param request GetJobStatusRequest
 * @param runtime runtime options for this request RuntimeOptions
 * @return GetJobStatusResponse
 */
async function getJobStatusWithOptions(request: GetJobStatusRequest, runtime: Util.RuntimeOptions): GetJobStatusResponse {
  Util.validateModel(request);
  var body : map[string]any = {};
  if (!Util.isUnset(request.jobId)) {
    body['JobId'] = request.jobId;
  }
  if (!Util.isUnset(request.vcName)) {
    body['VcName'] = request.vcName;
  }
  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'GetJobStatus',
    version = '2018-06-19',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

/**
 * @param request GetJobStatusRequest
 * @return GetJobStatusResponse
 */
async function getJobStatus(request: GetJobStatusRequest): GetJobStatusResponse {
  var runtime = new Util.RuntimeOptions{};
  return getJobStatusWithOptions(request, runtime);
}

model GetSparkSessionStateRequest {
  jobId?: string(name='JobId', description='This parameter is required.', example='j202104171040zjkb4cc449d0000000'),
}

model GetSparkSessionStateResponseBody = {
  requestId?: string(name='RequestId', example='9AD49396-8F80-5511-9268-A6360B205136'),
  state?: string(name='State', example='killed'),
}

model GetSparkSessionStateResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: GetSparkSessionStateResponseBody(name='body'),
}

/**
 * @param request GetSparkSessionStateRequest
 * @param runtime runtime options for this request RuntimeOptions
 * @return GetSparkSessionStateResponse
 */
async function getSparkSessionStateWithOptions(request: GetSparkSessionStateRequest, runtime: Util.RuntimeOptions): GetSparkSessionStateResponse {
  Util.validateModel(request);
  var body : map[string]any = {};
  if (!Util.isUnset(request.jobId)) {
    body['JobId'] = request.jobId;
  }
  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'GetSparkSessionState',
    version = '2018-06-19',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

/**
 * @param request GetSparkSessionStateRequest
 * @return GetSparkSessionStateResponse
 */
async function getSparkSessionState(request: GetSparkSessionStateRequest): GetSparkSessionStateResponse {
  var runtime = new Util.RuntimeOptions{};
  return getSparkSessionStateWithOptions(request, runtime);
}

model GetSparkStatementRequest {
  jobId?: string(name='JobId', description='This parameter is required.', example='j202106071620hangzhou00000000001'),
  statementId?: int32(name='StatementId', description='This parameter is required.', example='1'),
}

model GetSparkStatementResponseBody = {
  data?: {
    code?: string(name='Code', example='print(2+2)'),
    completedTime?: long(name='CompletedTime', example='1623033200754'),
    id?: int32(name='Id', example='1'),
    output?: string(name='Output', example='"{\\\\"status\\\\":\\\\"ok\\\\",\\\\"execution_count\\\\":1,\\\\"data\\\\":{\\\\"text/plain\\\\":\\\\"4\\\\"}}"'),
    process?: float(name='Process', example='0.5'),
    startedTime?: long(name='StartedTime', example='1623033200750'),
    state?: string(name='State', example='running'),
  }(name='Data'),
  requestId?: string(name='RequestId', example='C5DB60E0-6EB3-493C-8956-DA0D3A2EE656'),
}

model GetSparkStatementResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: GetSparkStatementResponseBody(name='body'),
}

/**
 * @param request GetSparkStatementRequest
 * @param runtime runtime options for this request RuntimeOptions
 * @return GetSparkStatementResponse
 */
async function getSparkStatementWithOptions(request: GetSparkStatementRequest, runtime: Util.RuntimeOptions): GetSparkStatementResponse {
  Util.validateModel(request);
  var body : map[string]any = {};
  if (!Util.isUnset(request.jobId)) {
    body['JobId'] = request.jobId;
  }
  if (!Util.isUnset(request.statementId)) {
    body['StatementId'] = request.statementId;
  }
  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'GetSparkStatement',
    version = '2018-06-19',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

/**
 * @param request GetSparkStatementRequest
 * @return GetSparkStatementResponse
 */
async function getSparkStatement(request: GetSparkStatementRequest): GetSparkStatementResponse {
  var runtime = new Util.RuntimeOptions{};
  return getSparkStatementWithOptions(request, runtime);
}

model KillSparkJobRequest {
  jobId?: string(name='JobId', description='This parameter is required.', example='j202011031935hangzhouf742a4330003667'),
  vcName?: string(name='VcName', description='This parameter is required.', example='MyCluster'),
}

model KillSparkJobResponseBody = {
  data?: string(name='Data', example='deleted'),
  requestId?: string(name='RequestId', example='3970ACB5-3E30-4A3A-B63A-1790FCC261F4'),
}

model KillSparkJobResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: KillSparkJobResponseBody(name='body'),
}

/**
 * @param request KillSparkJobRequest
 * @param runtime runtime options for this request RuntimeOptions
 * @return KillSparkJobResponse
 */
async function killSparkJobWithOptions(request: KillSparkJobRequest, runtime: Util.RuntimeOptions): KillSparkJobResponse {
  Util.validateModel(request);
  var body : map[string]any = {};
  if (!Util.isUnset(request.jobId)) {
    body['JobId'] = request.jobId;
  }
  if (!Util.isUnset(request.vcName)) {
    body['VcName'] = request.vcName;
  }
  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'KillSparkJob',
    version = '2018-06-19',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

/**
 * @param request KillSparkJobRequest
 * @return KillSparkJobResponse
 */
async function killSparkJob(request: KillSparkJobRequest): KillSparkJobResponse {
  var runtime = new Util.RuntimeOptions{};
  return killSparkJobWithOptions(request, runtime);
}

model ListSparkJobRequest {
  condition?: map[string]any(name='Condition', example='{   "createTime":"2020-12-28 09:00:00",   "jobName":"SparkPi" }'),
  pageNumber?: int32(name='PageNumber', description='This parameter is required.', example='1'),
  pageSize?: int32(name='PageSize', description='This parameter is required.', example='10'),
  vcName?: string(name='VcName', description='This parameter is required.', example='MySparkCluster'),
}

model ListSparkJobShrinkRequest {
  conditionShrink?: string(name='Condition', example='{   "createTime":"2020-12-28 09:00:00",   "jobName":"SparkPi" }'),
  pageNumber?: int32(name='PageNumber', description='This parameter is required.', example='1'),
  pageSize?: int32(name='PageSize', description='This parameter is required.', example='10'),
  vcName?: string(name='VcName', description='This parameter is required.', example='MySparkCluster'),
}

model ListSparkJobResponseBody = {
  dataResult?: {
    jobList?: [ 
      {
        createTime?: string(name='CreateTime', example='2020-10-27 17:51:05'),
        createTimeValue?: string(name='CreateTimeValue', example='1603792267000'),
        detail?: string(name='Detail', example='{"args":["100"],"name":...}'),
        driverResourceSpec?: string(name='DriverResourceSpec', example='small'),
        executorInstances?: string(name='ExecutorInstances', example='100'),
        executorResourceSpec?: string(name='ExecutorResourceSpec', example='small'),
        jobId?: string(name='JobId', example='j202010271750hangzhouf742a4330000950'),
        jobName?: string(name='JobName', example='SparkPi'),
        sparkUI?: string(name='SparkUI', example='https://dlaui-cn-hangzhou.aliyuncs.com/?token=xxx'),
        status?: string(name='Status', example='running'),
        submitTime?: string(name='SubmitTime', example='2020-10-27 17:51:05'),
        submitTimeValue?: string(name='SubmitTimeValue', example='1603792267000'),
        updateTime?: string(name='UpdateTime', example='2020-10-27 17:51:05'),
        updateTimeValue?: string(name='UpdateTimeValue', example='1603792267000'),
        vcName?: string(name='VcName', example='MyCluster'),
      }
    ](name='JobList'),
    pageNumber?: string(name='PageNumber', example='1'),
    pageSize?: string(name='PageSize', example='10'),
    totalCount?: string(name='TotalCount', example='4998'),
  }(name='DataResult'),
  requestId?: string(name='RequestId', example='E18B0634-F003-486A-90B9-4AA6932DA3AA'),
}

model ListSparkJobResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: ListSparkJobResponseBody(name='body'),
}

/**
 * @param tmpReq ListSparkJobRequest
 * @param runtime runtime options for this request RuntimeOptions
 * @return ListSparkJobResponse
 */
async function listSparkJobWithOptions(tmpReq: ListSparkJobRequest, runtime: Util.RuntimeOptions): ListSparkJobResponse {
  Util.validateModel(tmpReq);
  var request = new ListSparkJobShrinkRequest{};
  OpenApiUtil.convert(tmpReq, request);
  if (!Util.isUnset(tmpReq.condition)) {
    request.conditionShrink = OpenApiUtil.arrayToStringWithSpecifiedStyle(tmpReq.condition, 'Condition', 'json');
  }
  var query = {};
  if (!Util.isUnset(request.conditionShrink)) {
    query['Condition'] = request.conditionShrink;
  }
  if (!Util.isUnset(request.pageNumber)) {
    query['PageNumber'] = request.pageNumber;
  }
  if (!Util.isUnset(request.pageSize)) {
    query['PageSize'] = request.pageSize;
  }
  if (!Util.isUnset(request.vcName)) {
    query['VcName'] = request.vcName;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'ListSparkJob',
    version = '2018-06-19',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

/**
 * @param request ListSparkJobRequest
 * @return ListSparkJobResponse
 */
async function listSparkJob(request: ListSparkJobRequest): ListSparkJobResponse {
  var runtime = new Util.RuntimeOptions{};
  return listSparkJobWithOptions(request, runtime);
}

model ListSparkJobAttemptRequest {
  condition?: map[string]any(name='Condition', example='{"status":"success", "createTime":"2021-05-27 11:00:00", "timeZone":"Asia/Shanghai"}'),
  jobId?: string(name='JobId', description='This parameter is required.', example='j202105272322hangzhou5d64f1560000128'),
  pageNumber?: int32(name='PageNumber', description='This parameter is required.', example='1'),
  pageSize?: int32(name='PageSize', description='This parameter is required.', example='10'),
  vcName?: string(name='VcName', description='This parameter is required.', example='release-test'),
}

model ListSparkJobAttemptShrinkRequest {
  conditionShrink?: string(name='Condition', example='{"status":"success", "createTime":"2021-05-27 11:00:00", "timeZone":"Asia/Shanghai"}'),
  jobId?: string(name='JobId', description='This parameter is required.', example='j202105272322hangzhou5d64f1560000128'),
  pageNumber?: int32(name='PageNumber', description='This parameter is required.', example='1'),
  pageSize?: int32(name='PageSize', description='This parameter is required.', example='10'),
  vcName?: string(name='VcName', description='This parameter is required.', example='release-test'),
}

model ListSparkJobAttemptResponseBody = {
  dataResult?: {
    jobAttemptList?: [ 
      {
        createTime?: string(name='CreateTime', example='2021-05-27 23:22:08'),
        createTimeValue?: string(name='CreateTimeValue', example='1622128928000'),
        detail?: string(name='Detail', example='{"xxx":"xxx"}'),
        durationTime?: string(name='DurationTime', example='00:01:12'),
        durationTimeValue?: string(name='DurationTimeValue', example='72000'),
        jobAttemptId?: string(name='JobAttemptId', example='j202105272322hangzhou5d64f1560000128-0001'),
        jobId?: string(name='JobId', example='j202105272322hangzhou5d64f1560000128'),
        jobName?: string(name='JobName', example='xxx'),
        sparkUI?: string(name='SparkUI', example='xxx'),
        status?: string(name='Status', example='success'),
        terminatedTime?: string(name='TerminatedTime', example='2021-05-27 23:23:20'),
        terminatedTimeValue?: string(name='TerminatedTimeValue', example='1622129000000'),
        vcName?: string(name='VcName', example='release-test'),
      }
    ](name='JobAttemptList'),
    pageNumber?: string(name='PageNumber', example='1'),
    pageSize?: string(name='PageSize', example='10'),
    totalCount?: string(name='TotalCount', example='1'),
  }(name='DataResult'),
  requestId?: string(name='RequestId', example='4A839055-70C7-423D-A6F2-E714EA4502DB'),
}

model ListSparkJobAttemptResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: ListSparkJobAttemptResponseBody(name='body'),
}

/**
 * @param tmpReq ListSparkJobAttemptRequest
 * @param runtime runtime options for this request RuntimeOptions
 * @return ListSparkJobAttemptResponse
 */
async function listSparkJobAttemptWithOptions(tmpReq: ListSparkJobAttemptRequest, runtime: Util.RuntimeOptions): ListSparkJobAttemptResponse {
  Util.validateModel(tmpReq);
  var request = new ListSparkJobAttemptShrinkRequest{};
  OpenApiUtil.convert(tmpReq, request);
  if (!Util.isUnset(tmpReq.condition)) {
    request.conditionShrink = OpenApiUtil.arrayToStringWithSpecifiedStyle(tmpReq.condition, 'Condition', 'json');
  }
  var query = {};
  if (!Util.isUnset(request.conditionShrink)) {
    query['Condition'] = request.conditionShrink;
  }
  if (!Util.isUnset(request.jobId)) {
    query['JobId'] = request.jobId;
  }
  if (!Util.isUnset(request.pageNumber)) {
    query['PageNumber'] = request.pageNumber;
  }
  if (!Util.isUnset(request.pageSize)) {
    query['PageSize'] = request.pageSize;
  }
  if (!Util.isUnset(request.vcName)) {
    query['VcName'] = request.vcName;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'ListSparkJobAttempt',
    version = '2018-06-19',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

/**
 * @param request ListSparkJobAttemptRequest
 * @return ListSparkJobAttemptResponse
 */
async function listSparkJobAttempt(request: ListSparkJobAttemptRequest): ListSparkJobAttemptResponse {
  var runtime = new Util.RuntimeOptions{};
  return listSparkJobAttemptWithOptions(request, runtime);
}

model ListSparkStatementsRequest {
  jobId?: string(name='JobId', description='This parameter is required.', example='j202106071620hangzhou00000000001'),
}

model ListSparkStatementsResponseBody = {
  requestId?: string(name='RequestId', example='C2AB7692-B9EF-4A50-BCFF-0DC5B6F080E8'),
  statements?: [ 
    {
      code?: string(name='Code', example='print(2 + 2)'),
      completedTime?: long(name='CompletedTime', example='1623033200754'),
      id?: int32(name='Id', example='2'),
      output?: string(name='Output', example='{\\\\"status\\\\":\\\\"ok\\\\",\\\\"execution_count\\\\":1,\\\\"data\\\\":{\\\\"text/plain\\\\":\\\\"4\\\\"}}'),
      progress?: float(name='Progress', example='1'),
      startedTime?: long(name='StartedTime', example='1623033200750'),
      state?: string(name='State', example='running'),
    }
  ](name='Statements'),
}

model ListSparkStatementsResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: ListSparkStatementsResponseBody(name='body'),
}

/**
 * @param request ListSparkStatementsRequest
 * @param runtime runtime options for this request RuntimeOptions
 * @return ListSparkStatementsResponse
 */
async function listSparkStatementsWithOptions(request: ListSparkStatementsRequest, runtime: Util.RuntimeOptions): ListSparkStatementsResponse {
  Util.validateModel(request);
  var body : map[string]any = {};
  if (!Util.isUnset(request.jobId)) {
    body['JobId'] = request.jobId;
  }
  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'ListSparkStatements',
    version = '2018-06-19',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

/**
 * @param request ListSparkStatementsRequest
 * @return ListSparkStatementsResponse
 */
async function listSparkStatements(request: ListSparkStatementsRequest): ListSparkStatementsResponse {
  var runtime = new Util.RuntimeOptions{};
  return listSparkStatementsWithOptions(request, runtime);
}

model ReleaseInstanceRequest {
  instanceId?: string(name='InstanceId', description='This parameter is required.', example='dla-3qntmdtbqklsbsmceu****'),
  regionId?: string(name='RegionId', example='cn-beijing'),
}

model ReleaseInstanceResponseBody = {
  errorCode?: string(name='ErrorCode', example='600'),
  errorInfo?: string(name='ErrorInfo', example='An internal error occurred'),
  requestId?: string(name='RequestId', example='312F48C7-AFA0-46AA-B8F6-1B16B8808045'),
  result?: string(name='Result', example='true'),
  success?: boolean(name='Success', example='true'),
}

model ReleaseInstanceResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: ReleaseInstanceResponseBody(name='body'),
}

/**
 * @param request ReleaseInstanceRequest
 * @param runtime runtime options for this request RuntimeOptions
 * @return ReleaseInstanceResponse
 */
async function releaseInstanceWithOptions(request: ReleaseInstanceRequest, runtime: Util.RuntimeOptions): ReleaseInstanceResponse {
  Util.validateModel(request);
  var body : map[string]any = {};
  if (!Util.isUnset(request.instanceId)) {
    body['InstanceId'] = request.instanceId;
  }
  if (!Util.isUnset(request.regionId)) {
    body['RegionId'] = request.regionId;
  }
  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'ReleaseInstance',
    version = '2018-06-19',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

/**
 * @param request ReleaseInstanceRequest
 * @return ReleaseInstanceResponse
 */
async function releaseInstance(request: ReleaseInstanceRequest): ReleaseInstanceResponse {
  var runtime = new Util.RuntimeOptions{};
  return releaseInstanceWithOptions(request, runtime);
}

model SubmitSparkJobRequest {
  configJson?: string(name='ConfigJson', description='This parameter is required.', example='{     "name": "SparkPi",     "file": "local:///tmp/spark-examples.jar",     "className": "org.apache.spark.examples.SparkPi",     "args": [         "100"     ],     "conf": {         "spark.driver.resourceSpec": "medium",         "spark.executor.instances": 5,         "spark.executor.resourceSpec": "medium"     } }'),
  vcName?: string(name='VcName', description='This parameter is required.', example='MyCluster'),
}

model SubmitSparkJobResponseBody = {
  jobId?: string(name='JobId', example='j202011032013hangzhouf742a4330003679'),
  requestId?: string(name='RequestId', example='C039FD4D-2F3C-4556-AF09-864D3A6485B2'),
}

model SubmitSparkJobResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: SubmitSparkJobResponseBody(name='body'),
}

/**
 * @param request SubmitSparkJobRequest
 * @param runtime runtime options for this request RuntimeOptions
 * @return SubmitSparkJobResponse
 */
async function submitSparkJobWithOptions(request: SubmitSparkJobRequest, runtime: Util.RuntimeOptions): SubmitSparkJobResponse {
  Util.validateModel(request);
  var body : map[string]any = {};
  if (!Util.isUnset(request.configJson)) {
    body['ConfigJson'] = request.configJson;
  }
  if (!Util.isUnset(request.vcName)) {
    body['VcName'] = request.vcName;
  }
  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'SubmitSparkJob',
    version = '2018-06-19',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

/**
 * @param request SubmitSparkJobRequest
 * @return SubmitSparkJobResponse
 */
async function submitSparkJob(request: SubmitSparkJobRequest): SubmitSparkJobResponse {
  var runtime = new Util.RuntimeOptions{};
  return submitSparkJobWithOptions(request, runtime);
}

model SubmitSparkSQLRequest {
  sql?: string(name='Sql', description='This parameter is required.', example='set spark.driver.resourceSpec=medium;set spark.executor.instances=5;  set spark.executor.resourceSpec=medium;  set spark.app.name=sparksqltest;  show databases;'),
  vcName?: string(name='VcName', description='This parameter is required.', example='MySparkCluster'),
}

model SubmitSparkSQLResponseBody = {
  jobId?: string(name='JobId', example='j202104261729hangzhou224ee5230000930'),
  requestId?: string(name='RequestId', example='B570310A-8A49-461B-B81D-AE0B58D63DA4'),
}

model SubmitSparkSQLResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: SubmitSparkSQLResponseBody(name='body'),
}

/**
 * @param request SubmitSparkSQLRequest
 * @param runtime runtime options for this request RuntimeOptions
 * @return SubmitSparkSQLResponse
 */
async function submitSparkSQLWithOptions(request: SubmitSparkSQLRequest, runtime: Util.RuntimeOptions): SubmitSparkSQLResponse {
  Util.validateModel(request);
  var body : map[string]any = {};
  if (!Util.isUnset(request.sql)) {
    body['Sql'] = request.sql;
  }
  if (!Util.isUnset(request.vcName)) {
    body['VcName'] = request.vcName;
  }
  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'SubmitSparkSQL',
    version = '2018-06-19',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

/**
 * @param request SubmitSparkSQLRequest
 * @return SubmitSparkSQLResponse
 */
async function submitSparkSQL(request: SubmitSparkSQLRequest): SubmitSparkSQLResponse {
  var runtime = new Util.RuntimeOptions{};
  return submitSparkSQLWithOptions(request, runtime);
}

model ValidateVirtualClusterNameRequest {
  vcName?: string(name='VcName', example='abc123'),
}

model ValidateVirtualClusterNameResponseBody = {
  data?: {
    legal?: string(name='Legal', example='true'),
    message?: string(name='Message', example='null'),
  }(name='Data'),
  requestId?: string(name='RequestId', example='C039FD4D-2F3C-4556-AF09-864D3A6485B2'),
}

model ValidateVirtualClusterNameResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: ValidateVirtualClusterNameResponseBody(name='body'),
}

/**
 * @param request ValidateVirtualClusterNameRequest
 * @param runtime runtime options for this request RuntimeOptions
 * @return ValidateVirtualClusterNameResponse
 */
async function validateVirtualClusterNameWithOptions(request: ValidateVirtualClusterNameRequest, runtime: Util.RuntimeOptions): ValidateVirtualClusterNameResponse {
  Util.validateModel(request);
  var body : map[string]any = {};
  if (!Util.isUnset(request.vcName)) {
    body['VcName'] = request.vcName;
  }
  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'ValidateVirtualClusterName',
    version = '2018-06-19',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

/**
 * @param request ValidateVirtualClusterNameRequest
 * @return ValidateVirtualClusterNameResponse
 */
async function validateVirtualClusterName(request: ValidateVirtualClusterNameRequest): ValidateVirtualClusterNameResponse {
  var runtime = new Util.RuntimeOptions{};
  return validateVirtualClusterNameWithOptions(request, runtime);
}

